package com.zhongwei.lvzhixuanmanage.utils;

import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.ExcelWriter;
import com.alibaba.excel.write.metadata.WriteSheet;
import com.zhongwei.lvzhixuanmanage.entity.Order;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 *
 * @Author: 施灿彬
 * @Date: 2022/07/09
 * @Param response 对象
 * @Param
 * @Description:
 */
public class ExcelUtils {
    public static void writeExcel(HttpServletResponse response, List<Order> list) throws IOException {
        ExcelWriter excelWriter = EasyExcel.write(response.getOutputStream()).build();

        response.setCharacterEncoding("UTF-8");
        response.setHeader("content-type","text/html;charset = UTF-8");
        WriteSheet sheet = EasyExcel.writerSheet(0,"sheet").head(Order.class).build();

        //在excel中写入数据
        excelWriter.write(list,sheet);
        //关闭输出流
        excelWriter.finish();
    }
}
